package orest.front.achieve;

import net.ssta.core.db.Record;
import net.ssta.core.db.RecordSet;
import orest.common.response.Response;
import java.util.ArrayList;
import java.util.Iterator;
import orest.common.util.*;
import orest.common.valueobject.*;

public class GetOptionAction {
    
    /** Creates a new instance of ProvinceAction */
    public GetOptionAction () {
    }
     
    
      
      
     public String getFieldOptionListBytnfn(String tablename,String fieldname,String optionval){
         GetOption         obj      = new GetOption();
        StringBuffer        result   = new StringBuffer();
        
        boolean            opReturn = true;
        String              tempstr  = "";
        
        ArrayList al = obj.getFieldOptionListBytnfn(tablename,fieldname);
        Iterator iterator = al.iterator ();
        RecordSet rSet = new RecordSet();
        Record rcd = new Record();
        rcd.addData("optionname", fieldname);
        rcd.addData("optionval", optionval);
        rSet.add(rcd);
        try{
        	
            while(iterator.hasNext ()){
            	Record record = new Record();
                FieldOptionVal objElem = (FieldOptionVal)iterator.next();
                result.append("<id>");
                result.append (objElem.getId());
                record.addData("id", objElem.getId());
                result.append ("</id>");
                result.append("<name>");
                result.append (objElem.getOptionName());
                
                if(objElem.getId().indexOf(".")!=-1){
                	record.addData("name", "——"+objElem.getOptionName());
                }else{
                	record.addData("name", objElem.getOptionName());
                }
                
                
                
                result.append ("</name>");
                objElem = null;
                rSet.add(record);
            }
        }
        catch(Exception e) {
            System.out.println ("when encoding the string, exception occured.");
            System.out.println ("The class is GetOptionAction and the function is " +
                                 "getAppraiseUnitList()");
        }

        al = null;
        obj = null;
        //return result.toString ();
        return rSet.getJsonString();
     }
     
     
     
     public String getFieldOptionListBytnfn_ckeck(String tablename,String fieldname,String optionval){
         GetOption         obj      = new GetOption();
        StringBuffer        result   = new StringBuffer();
        
        boolean            opReturn = true;
        String              tempstr  = "";
        
        ArrayList al = obj.getFieldOptionListBytnfn(tablename,fieldname);
        Iterator iterator = al.iterator ();
        RecordSet rSet = new RecordSet();
        Record rcd = new Record();
        rcd.addData("optionname", fieldname);
        rcd.addData("optionval", optionval);
        rSet.add(rcd);
        try{
        	
            while(iterator.hasNext ()){
            	Record record = new Record();
                FieldOptionVal objElem = (FieldOptionVal)iterator.next();
                result.append("<id>");
                result.append (objElem.getId());
                record.addData("id", objElem.getId());
                result.append ("</id>");
                result.append("<name>");
                result.append (objElem.getOptionName());
                
                record.addData("name", objElem.getOptionName());
                
                
                
                result.append ("</name>");
                objElem = null;
                rSet.add(record);
            }
        }
        catch(Exception e) {
            System.out.println ("when encoding the string, exception occured.");
            System.out.println ("The class is GetOptionAction and the function is " +
                                 "getAppraiseUnitList()");
        }

        al = null;
        obj = null;
        //return result.toString ();
        return rSet.getJsonString();
     }
     
     
     
    
     public String getProvinceList(){
         GetOption         obj      = new GetOption();
        StringBuffer        result   = new StringBuffer();
        Tools tool = new Tools();
        boolean            opReturn = true;
        String              tempstr  = "";
        
        ArrayList al = obj.getProvinceList();
        Iterator iterator = al.iterator ();
        RecordSet rSet = new RecordSet();
        try{
            while(iterator.hasNext ()){
            	Record record = new Record();
                ProvinceVal objElem = (ProvinceVal)iterator.next();
                result.append("<id>");
                result.append (objElem.getProvinceId());
                record.addData("id",objElem.getProvinceId());
                result.append ("</id>");
                
                result.append("<name>");
                result.append (objElem.getProvinceName());
                record.addData("name", objElem.getProvinceName());
                result.append ("</name>");
                objElem = null;
                rSet.add(record);
            }
        }
        catch(Exception e) {
            System.out.println ("when encoding the string, exception occured.");
            System.out.println ("The class is GetOptionAction and the function is " +
                                 "getProvinceList()");
        }
        al = null;
        obj = null;
        //return result.toString ();
        return rSet.getJsonString();
     }
     
      public String getZdxxList(String zddm,String xxdm){
         GetOption         obj      = new GetOption();
        StringBuffer        result   = new StringBuffer();
        
        boolean            opReturn = true;
        String              tempstr  = "";
        
        ArrayList al = obj.getZdxxList(zddm);
        Iterator iterator = al.iterator ();
        RecordSet rSet = new RecordSet();
        try{
        	Record rcd = new Record();
        	rcd.addData(zddm, xxdm);
        	rSet.add(rcd);
            while(iterator.hasNext ()){
            	Record record = new Record();
                ProvinceVal objElem = (ProvinceVal)iterator.next();
                result.append("<id>");
                result.append (objElem.getProvinceId());
                record.addData("id", objElem.getProvinceId());
                result.append ("</id>");
                result.append("<name>");
                result.append (objElem.getProvinceName());
                record.addData("name", objElem.getProvinceName());
                result.append ("</name>");
                objElem = null;
                rSet.add(record);
            }
        }
        catch(Exception e) {
            System.out.println ("when encoding the string, exception occured.");
            System.out.println ("The class is GetOptionAction and the function is " +
                                 "getProvinceList()");
        }
        al = null;
        obj = null;
       // return result.toString ();
        return rSet.getJsonString();
     }
      
      
      public String getZdxxList_check(String zddm,String xxdm){
          GetOption         obj      = new GetOption();
         StringBuffer        result   = new StringBuffer();
         
         boolean            opReturn = true;
         String              tempstr  = "";
         
         ArrayList al = obj.getZdxxList(zddm);
         Iterator iterator = al.iterator ();
         RecordSet rSet = new RecordSet();
         try{
         	Record rcd = new Record();
         	rcd.addData(zddm, xxdm);
         	rSet.add(rcd);
             while(iterator.hasNext ()){
             	Record record = new Record();
                 ProvinceVal objElem = (ProvinceVal)iterator.next();
                 result.append("<id>");
                 result.append (objElem.getProvinceId());
                 record.addData("id", objElem.getProvinceId());
                 result.append ("</id>");
                 result.append("<name>");
                 result.append (objElem.getProvinceName());
                 record.addData("name", objElem.getProvinceName());
                 result.append ("</name>");
                 objElem = null;
                 rSet.add(record);
             }
         }
         catch(Exception e) {
             System.out.println ("when encoding the string, exception occured.");
             System.out.println ("The class is GetOptionAction and the function is " +
                                  "getProvinceList()");
         }
         al = null;
         obj = null;
        // return result.toString ();
         return rSet.getJsonString();
      }
     
     
}
